﻿<Settings>
  <setting name="JsonRules">
    <value>
      <![CDATA[
      {
        "RulesForEntities": [
          {
              "Key": "contact", "Value":
                {
                    "EntityName": "contact", "Rules": [
                      {
                        "Name": "Validate entire operation against value in grandparent record: Primary Contact of Account associated with this Contact must have CreditHold=No. NOTE: this validator ONLY looks at a value in related record. On failure, send email and stop operation.",
                        "SourceSetting": {
							            "ReactToAnyFieldChange": "true",
                          "FieldName": "annualincome",
                          "FieldValidators": [
                          {
                              "Name": "Validate entire operation against value in grandparent record: Primary Contact of Account associated with this Contact must have CreditHold=No. NOTE: this validator ONLY looks at a value in related record",
                              "ValidatedFieldIsInRelatedRecord": "true",
								              "ThrowExceptionWhenInvalid": "true",
								              "AdditionalErrorMessage": "Primary Contact record associated with Parent Account of current Contact Record has Credit Hold. Current Record is in locked status.",
                              "Action": {
                                  "ActionKind": "SendEmail",
                                  "EntityLogicalName": "contact"
                              },
                              "Range": {
                                  "RangeValidationKind": "Equals",
                                  "ParentEntityFetchQuery": "<fetch distinct='false' mapping='logical' aggregate='false'> <entity name='contact'><attribute name='fullname' /> <filter type='and'><condition attribute='contactid' operator='eq' value='<PK_VALUE>' /> </filter> <link-entity name='account' to='parentcustomerid' from='accountid' alias='acc' link-type='inner'>  <attribute name='name'/><link-entity name='contact' to='primarycontactid' from='contactid' alias='grands' link-type='inner'>  <attribute name='fullname'/><attribute name='creditonhold'/></link-entity></link-entity></entity> </fetch>",
                                  "EqualsValue": {
                                      "CrmFieldType": "CrmBoolean",
                                      "Name": "grands.creditonhold",
                                      "Value": false
                                  }
                              }
                          }],
                          "RollupOperation": { "OperationType": "NoOp" }
                        }
                      }]
                }
          }]
    }
      ]]>
    </value>
  </setting>
</Settings>